home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DOS.SWG / 0077_Redirection with Output Var.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  2KB  |  62 lines

  1. {
  2.  Small program to demostrate redirection of TP's Output variable
  3.  Arne de Bruijn, 1994, PD
  4. }
  5.  
  6. Unit SmallCrt;
  7. interface
  8. procedure AssignCrt(var F:text);
  9. implementation
  10. uses Dos; {For TextRec, fmClosed, fmOutput}
  11.  
  12. function InOutCrtOut(var F:text):byte; far; assembler;
  13. asm
  14.  cld                          { Count forwards }
  15.  mov dx,ds                    { Save DS }
  16.  lds si,F                     { Get address of F }
  17.  mov cx,[si].TextRec.BufPos   { Get number of bytes to write }
  18.  lds si,[si].TextRec.BufPtr   { Get address of buffer }
  19. @OutChars:
  20.  lodsb                        { Load character to output in AL, and }
  21.                               { set SI to next character }
  22.  int 29h                      { Output AL with DOS undocumented fast write }
  23.  loop @OutChars               { Do all characters (dec(cx); until cx=0) }
  24.  mov ds,dx                    { Restore DS }
  25. end;
  26.  
  27. function CloseCrtOut(var F:text):byte; far;
  28. begin
  29.  TextRec(F).Mode:=fmClosed;
  30.  CloseCrtOut:=0;
  31. end;
  32.  
  33. function OpenCrtOut(var F:text):byte; far;
  34. begin
  35.  with TextRec(F) do
  36.   begin
  37.    Mode:=fmOutput;
  38.    BufPos:=0; BufEnd:=0;
  39.    InOutFunc:=@InOutCrtOut;
  40.    FlushFunc:=@InOutCrtOut;
  41.    CloseFunc:=@CloseCrtOut;
  42.   end;
  43.  OpenCrtOut:=0;
  44. end;
  45.  
  46. procedure AssignCrt(var F:text);
  47. begin
  48.  with TextRec(F) do
  49.   begin
  50.    Mode:=fmClosed;
  51.    BufSize:=SizeOf(Buffer);
  52.    BufPtr:=@Buffer;
  53.    Name[0]:=#0;
  54.    OpenFunc:=@OpenCrtOut;
  55.   end;
  56. end;
  57.  
  58. begin
  59.  AssignCrt(Output);
  60.  Rewrite(Output);
  61. end.
  62.